<?php
header('content-type:text/html;charset=utf-8');
include '../functions.php';

if (isset($_FILES['file']['name'])and$_FILES['file']['name']){
date_default_timezone_set('PRC');
//把上传进来的图像数组分解
$file = pathinfo($_FILES['file']['name']);

//从新命名
$ming = 'uploads/'.time().'.'.$file['extension'];

//将上传的文件移动到新文件夹里面
move_uploaded_file($_FILES['file']['tmp_name'],$ming);

$re = include 'xuyuanchang.php';

$re[] = array(
    'username'=>$_POST['username'],
    'content'=>$_POST['content'],
    'time'=>date('y/m/d h:i:s'),
    'ming'=>time().'.'.$file['extension']
);

$str ="<?php \n\r return ".var_export($re,true)."\n\r ?>";

file_put_contents('xuyuanchang.php',$str);

echo '
<script>
alert(\'留言成功\');
location.href=\'index.php\'</script>';
}